﻿<UserControl x:Class="MediaAssistant.Controls.PlayingMusicInfo.PlayingMusicInfoInfoView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Converters="clr-namespace:MediaAssistant.Converters" mc:Ignorable="d" 
             Width="Auto" Height="Auto">
    <UserControl.Resources>
        <Converters:MusicToTitleConverter x:Key="MusicToTitleConverter" />
        <Converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter" />
        <Converters:TimeSpanToTextConverter x:Key="TimeSpanToTextConverter" />
        <Converters:DurationToMilisecondConverter x:Key="DurationToMilisecondConverter" />
        <Converters:TimeSpanToMilisecondConverter x:Key="TimeSpanToMilisecondConverter" />
        <Style x:Key="ThumbBall" TargetType="{x:Type Thumb}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Path StrokeThickness="0.250000" Stroke="{StaticResource DarkestBackground}" StrokeMiterLimit="1.000000" Data="F1 M 0,3.455078 C 0,1.615723 1.490234,0.125000 3.330078,0.125000 C 5.168945,0.125000 6.659179,1.615723 6.659179,3.455078 C 6.659179,5.292969 5.168945,6.784180 3.330078,6.784180 C 1.490234,6.784180 0,5.292969 0,3.455078 Z" 
                              x:Name="TrackBall" Opacity="0.75" Fill="{StaticResource DarkestBackground}" />
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="TrackBall" Property="Opacity" Value="1"/>
                                <Setter Property="Cursor" Value="Hand"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter TargetName="TrackBall" Property="Opacity" Value="0.5"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="SliderStyle" TargetType="{x:Type Slider}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Slider}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <ProgressBar Grid.Row="1" Minimum="{TemplateBinding Minimum}"  Maximum="{TemplateBinding Maximum}" Value="{TemplateBinding Value}"/>
                            <Track Grid.Row="1" Name="PART_Track" Visibility="Visible">
                                <Track.Thumb>
                                    <Thumb Style="{StaticResource ThumbBall}" />
                                </Track.Thumb>
                            </Track>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <DockPanel Visibility="{Binding DataSource.PlayingMusic, Converter={StaticResource NotNullToVisibilityConverter}}" HorizontalAlignment="Left">
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Center" MinWidth="200">
            <TextBlock Text="{Binding DataSource.PlayingMusic.Artist}" TextAlignment="Center" ToolTip="Current Artist Music" />
            <TextBlock Margin="10,0,0,0" Text="{Binding DataSource.PlayingMusic, Converter={StaticResource MusicToTitleConverter}}" TextAlignment="Center" FontWeight="DemiBold" ToolTip="Current Music" />
        </StackPanel>
        <DockPanel DockPanel.Dock="Bottom" Height="15" HorizontalAlignment="Stretch" Width="400">
            <TextBlock DockPanel.Dock="Left" Width="45" Text="{Binding DataSource.Position, Converter={StaticResource TimeSpanToTextConverter}}" TextAlignment="Right" FontSize="10" Margin="3,0,0,0" ToolTip="Current music time" />
            <TextBlock DockPanel.Dock="Right"  Width="45" Text="{Binding DataSource.TimeRemains, Converter={StaticResource TimeSpanToTextConverter}}" FontSize="10" Margin="0,0,3,0" ToolTip="Remains music time" />
            <Slider Margin="3" FontSize="10" Minimum="0" SmallChange="1" Style="{StaticResource SliderStyle}"
                             Maximum="{Binding DataSource.NaturalDuration, Converter={StaticResource DurationToMilisecondConverter}}"
                             Value="{Binding DataSource.Position, Converter={StaticResource TimeSpanToMilisecondConverter}}" ToolTip="Drag it to return/advance music time" />
        </DockPanel>
    </DockPanel>
</UserControl>
